<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>下载课程</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="X-Frame-Options" content="DENY">
    <link rel="stylesheet" href="./lib/css/layui.css" media="all">

</head>

<body>
    <form class="layui-form layui-row" action="" lay-filter="mainForm" style="width: 90%;padding: 10px;">        
        <div class="layui-form-item ">
          <label class="layui-form-label">参考评测:</label>
          <div class="layui-input-block">
            <select name="firstTest" id="firstTest"></select>
          </div>
        </div>          
        <div class="layui-form-item">
            <div>
                <button type="button" id="downCourse" class="layui-btn layui-btn-warm" style="float: right;">下载课程包</button>
            </div>
        </div>  
        <div class="layui-form-item ">
            <label class="layui-form-label">参考复测:</label>
            <div class="layui-input-block">
              <select name="reTest" id="reTest"></select>
            </div>
        </div>  
        <div class="layui-form-item ">
            <label class="layui-form-label">期数:</label>
            <div class="layui-input-block">
              <select name="phase" id="phase">
                <option value="1">第一期</option>
                <option value="2">第二期</option>
                <option value="3">第三期</option>
                <option value="4">第四期</option>
                <option value="5">第五期</option>
                <option value="6">第六期</option>
                <option value="7">第七期</option>
                <option value="8">第八期</option>                
              </select>
            </div>
        </div>  
        <div class="layui-form-item">
            <div>
                <button type="button" id="downCourseFile" class="layui-btn layui-btn-warm" style="float: right;">下载课程文件</button>
            </div>
        </div>  
      </form>
    <script src="./lib/layui.js" charset="utf-8"></script>
    <script src="./config.js"></script>
    <script>

        layui.use(["form", "jquery","layer"], function () {
            var form = layui.form;
            var $ = layui.$;
            var layer = layui.layer;
            $("#downCourse").click(function(){   
                var data=form.val("mainForm");
                if(!data.firstTest){
                    layer.msg("请选择参考评测")
                    return false;
                }
                window.top.location.href=requestUrl+"/service/focus-service/device/publicApi/exportCourse?testId="+data.firstTest
                
            })            
            $("#downCourseFile").click(function(){
                var data=form.val("mainForm");
                if(!data.firstTest){
                    layer.msg("请选择参考评测")
                    return false;
                }
                var testId=data.firstTest;
                var reTestId=data.firstTest;                
                if(data.phase!="1"){
                    if(!data.reTest){
                        layer.msg("请选择参考复测")
                        return false;
                    }else{
                        reTestId=data.reTest;
                    }
                }
                window.top.location.href=requestUrl+"/service/focus-service/device/publicApi/downloadCourse?testId="
                +testId+"&reTestId="+reTestId+"&phase="+data.phase;
                return false;
            })
            $(function(){
                request($,"get",requestUrl+"/service/focus-service/device/tests",
                {memberId:getQueryString("id"),check_type:0,pageSize:10,pageIndex:1},
                function(res){
                    for(var i=0;i<res.content.length;i++){
                        $("#firstTest").append("<option value='"+res.content[i].id+"'> ("+res.content[i].teacher
                            +") 在 ["+res.content[i].testDate+"] 做的评测</option>")
                    }                    
                    form.render("select");
                })
                request($,"get",requestUrl+"/service/focus-service/device/tests",
                {memberId:getQueryString("id"),check_type:1,pageSize:10,pageIndex:1},
                function(res){
                    for(var i=0;i<res.content.length;i++){
                        $("#reTest").append("<option value='"+res.content[i].id+"'> ("+res.content[i].teacher
                            +") 在 ["+res.content[i].testDate+"] 做的评测</option>")
                    }                    
                    form.render("select");
                })
            })

        });
        
        function getQueryString(name) {
            var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return unescape(r[2]);
            }
            return null;
        }
        function request($, type, url, data, success) {
            $.ajax({
                url: url,
                data: data,
                type: type,
                headers: { Authorization: "bearer " + getQueryString('token') },
                success: function (res) {
                    success(res)
                }
            })
        } 
    </script>
</body>

</html>